<?php
/*
 * 短信类
 */
class Sms
{
	/*
	 * $arr['username'] = $name;
       $arr['password'] = $password;
       Sms::send(1, $tel, $arr);
	 */
	//1 注册成功 SMS_3725050
	//2 找回密码 SMS_3700090
	//3 匹配成功 SMS_3690075
	//4 支付成功 SMS_3670049
	//5 确认付款 SMS_3660090
	//6注册验证码
	//7审核通过通知短信
	//private static $smsType = array(1=>'SMS_14755127',2=>'SMS_14780192',3=>'SMS_14755129',4=>'SMS_14690139',5=>'SMS_14735216');
    private static $smsType = array(1=>'SMS_6950088',2=>'SMS_16736970',3=>'SMS_6925130',4=>'SMS_6980127',5=>'SMS_7310118',6=>'SMS_31940002',7=>'SMS_31810004');
	
	//获取短信验证码字符串
	static function getSmsParamStr($type, $arr)
	{
		if($type === 1 )//注册成功
		{
			return "{\"name\":\"{$arr['username']}\",\"password\":\"{$arr['password']}\"}";
		   // return "{\"name\":\"{$arr['username']}\"}";
		}
		elseif($type === 2)//找回密码
		{
			return "{\"name\":\"{$arr['username']}\",\"valicode\":\"{$arr['valicode']}\"}";
		}
		elseif($type === 3 || $type === 4 || $type === 5)//3匹配成功 4支付  5确认付款
		{
			return "{\"name\":\"{$arr['username']}\"}";
			//return null;
		}
		elseif($type === 6)//注册激活码短信
		{
		    return "{\"code\":\"{$arr['code']}\"}";
		}
		elseif($type === 7)//审核通过
		{
		    return "{\"name\":\"{$arr['username']}\"}";
		}
	}
	
	
	public static function send($type,$to_mobile, $arr)
	{
		$status = Common::getConfigJjsetValue("jjset_sms_send");
		if(intval($status) !== 0)//根据后台开关设置判断是否发送短信
		{
			include_once "taobao-sdk-PHP/TopSdk.php";
			date_default_timezone_set('Asia/Shanghai');
			 
			$c = new TopClient();
			
			$appkey = '23334675';
			
			$secret = '98b4bc73aa6b6f48cee1dac73d36277d';
			
			$c->appkey = $appkey;
			$c->secretKey = $secret;
			$req = new AlibabaAliqinFcSmsNumSendRequest;
			//公共回传参数
			$req->setExtend("123456");
			//短信类型，为固定值normal
			$req->setSmsType("normal");
			
			//短信签名
			$req->setSmsFreeSignName("创云商城");
			
			//短信模板变量
			$smsParameterStr = self::getSmsParamStr($type, $arr);
			
			$req->setSmsParam($smsParameterStr);
			
			//接受短信的号码,多个手机号用逗号隔开
			$req->setRecNum("$to_mobile");
			
			//短信模板id
			$smsTemCode = self::$smsType[$type];
			
			$req->setSmsTemplateCode($smsTemCode);
			$resp = $c->execute($req);
			
			return $resp;
		}
		
	}
	
	
	
	
	
	/**
	 * 短信模板
	 * 您的账号${name}于${time}成功登录${ptname}后台管理中心，登录IP地址为${addr} 
	 * Enter description here ...
	 * @param unknown_type $type
	 * @param unknown_type $to_mobile
	 * @param unknown_type $arr
	 */
	
	public static function admin_login_send($manager_id, $ip)
	{
		$status = Common::getConfigJjsetValue("jjset_sms_send");
		if(intval($status) !== 0)//根据后台开关设置判断是否发送短信
		{
			include_once "taobao-sdk-PHP/TopSdk.php";
			date_default_timezone_set('Asia/Shanghai');
			 
			$c = new TopClient();
			
			$appkey = '23297940';
			
			$secret = '8ea401919e9aacf913eaefdf07ce30f2';
			
			$c->appkey = $appkey;
			$c->secretKey = $secret;
			$req = new AlibabaAliqinFcSmsNumSendRequest;
			//公共回传参数
			$req->setExtend("123456");
			//短信类型，为固定值normal
			$req->setSmsType("normal");
			
			//短信签名
			$req->setSmsFreeSignName("身份验证");
			
			//短信模板变量
			//$smsParameterStr = self::getSmsParamStr($type, $arr);
			
			$ntime = date("Y-m-d H:i:s", time());
			
			$config = Common::getConfigValue("globals");
			$ptname = $config['site_name'];
			
			$model = new Model();
			$manager_obj = $model->table("manager")->where("id=".$manager_id)->find();
			$name = $manager_obj['name'];
			
			$smsParameterStr = "{\"name\":\"{$name}\",\"time\":\"{$ntime}\",\"ptname\":\"{$ptname}\",\"addr\":\"{$ip}\"}";
			$req->setSmsParam($smsParameterStr);
			
			$to_mobile = Common::getConfigJjsetValue("jjset_admin_mobile_number");
			//接受短信的号码,多个手机号用逗号隔开
			$req->setRecNum("$to_mobile");
			
			//短信模板id
			//$smsTemCode = self::$smsType[$type];
			$smsTemCode = "SMS_6180073";
			$req->setSmsTemplateCode($smsTemCode);
			$resp = $c->execute($req);
			
			return $resp;
		}
		
	}
	
	
	
}
?>